package com.zygh.policeasset.utils;

import com.sun.xml.bind.v2.runtime.reflect.opt.Const;
import com.zygh.policeasset.component.SpringJobBeanFactory;
import com.zygh.policeasset.pojo.DepRate;
import com.zygh.policeasset.service.ExcelService;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/utils/DepRateByTimeUtil.class */
public class DepRateByTimeUtil {
    @Async("asyncTaskExecutor")
    public List<DepRate> getDepRateNew(List<DepRate> depRateList, String time1, String time2, Integer condition) throws ParseException, IllegalAccessException {
        SimpleDateFormat sdff = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Iterator<DepRate> it = depRateList.iterator();
        while (it.hasNext()) {
            DepRate depRate = it.next();
            System.out.println(depRate);
            DepRate depRate2 = ((ExcelService) SpringJobBeanFactory.getBean(ExcelService.class)).setProjectName(depRate);
            calendar.setTime(sdff.parse(depRate2.getStartProvisionDate()));
            calendar.add(1, Integer.parseInt(depRate2.getDepreciationYear()));
            Date aftertime = sdff.parse(sdff.format(calendar.getTime()));
            Date stoptime = sdff.parse(depRate2.getStartProvisionDate());
            Date time1Date = sdff.parse(time1);
            Date time2Date = sdff.parse(time2);
            Double money = Double.valueOf(depRate2.getMoney());
            int rate = Integer.valueOf(String.valueOf(depRate2.getDepreciationYear())).intValue() * 12;
            depRate2.setMoney(String.valueOf(money));
            double monthly = Arith.div(money.doubleValue(), (double) rate, 0);
            if (stoptime.before(time1Date) && time2Date.before(aftertime)) {
                double depreciated = Arith.mul(monthly, (double) getCountMonth(time1Date, time2Date), 0);
                depRate2.setDepreciated(Double.valueOf(depreciated));
                double beginningOfPeriod = Arith.sub(money.doubleValue(), Arith.mul(monthly, (double) getCountMonth(stoptime, time1Date), 0), 5);
                depRate2.setBeginningOfPeriod(Double.valueOf(beginningOfPeriod));
                double bookMoney = Arith.sub(beginningOfPeriod, depreciated, 5);
                depRate2.setBookMoney(Double.valueOf(bookMoney));
                if (bookMoney < depreciated) {
                    depRate2.setDepreciated(Double.valueOf(Arith.add(depreciated, bookMoney, 5)));
                    depRate2.setBookMoney(Double.valueOf((double) Const.default_value_double));
                }
                if (0 == getCountMonth(stoptime, time1Date)) {
                    depRate2.setNewAddition(money);
                }
                if ((Const.default_value_double == bookMoney) && (0 == condition.intValue())) {
                    it.remove();
                }
            } else if (time1Date.before(stoptime) && aftertime.before(time2Date)) {
                depRate2.setDepreciated(money);
                depRate2.setBeginningOfPeriod(Double.valueOf(Double.parseDouble("0")));
                depRate2.setBookMoney(Double.valueOf(Double.parseDouble("0")));
                if (0 == condition.intValue()) {
                    it.remove();
                }
            } else if (aftertime.before(time1Date)) {
                depRate2.setDepreciated(Double.valueOf(Double.parseDouble("0")));
                depRate2.setBeginningOfPeriod(Double.valueOf(Double.parseDouble("0")));
                depRate2.setBookMoney(Double.valueOf(Double.parseDouble("0")));
                if (0 == condition.intValue()) {
                    it.remove();
                }
            } else if (time2Date.compareTo(stoptime) < 0) {
                depRate2.setDepreciated(Double.valueOf(Double.parseDouble("0")));
                depRate2.setBeginningOfPeriod(Double.valueOf(Double.parseDouble("0")));
                depRate2.setBookMoney(money);
                if (0 == condition.intValue()) {
                    it.remove();
                }
            } else if (time2Date.compareTo(stoptime) == 0) {
                depRate2.setDepreciated(Double.valueOf(monthly));
                depRate2.setBeginningOfPeriod(money);
                depRate2.setBookMoney(Double.valueOf(Arith.sub(money.doubleValue(), monthly, 5)));
            } else if (stoptime.before(time1Date) && time1Date.before(aftertime) && aftertime.before(time2Date)) {
                double depreciatedd = Arith.sub(money.doubleValue(), Arith.mul(monthly, (double) getCountMonth(stoptime, time1Date), 0), 5);
                depRate2.setDepreciated(Double.valueOf(depreciatedd));
                depRate2.setBeginningOfPeriod(Double.valueOf(depreciatedd));
                depRate2.setBookMoney(Double.valueOf((double) Const.default_value_double));
                if (0 == condition.intValue()) {
                    it.remove();
                }
            } else if (time1Date.before(stoptime) && stoptime.before(time2Date) && time2Date.before(aftertime)) {
                double depreciated2 = Arith.mul(monthly, (double) getCountMonth(stoptime, time2Date), 0);
                depRate2.setDepreciated(Double.valueOf(depreciated2));
                depRate2.setBeginningOfPeriod(Double.valueOf((double) Const.default_value_double));
                double bookMoney2 = Arith.sub(money.doubleValue(), depreciated2, 5);
                depRate2.setBookMoney(Double.valueOf(bookMoney2));
                if (bookMoney2 < depreciated2) {
                    depRate2.setDepreciated(Double.valueOf(Arith.add(depreciated2, bookMoney2, 5)));
                    depRate2.setBookMoney(Double.valueOf((double) Const.default_value_double));
                }
                if (0 == getCountMonth(stoptime, time1Date)) {
                    depRate2.setNewAddition(money);
                }
                if ((Const.default_value_double == bookMoney2) && (0 == condition.intValue())) {
                    it.remove();
                }
            }
        }
        return depRateList;
    }

    public static int getCountMonth(Date time1, Date time2) {
        Calendar bef = Calendar.getInstance();
        Calendar aft = Calendar.getInstance();
        bef.setTime(time1);
        aft.setTime(time2);
        int num = ((aft.get(1) - bef.get(1)) * 12) + (aft.get(2) - bef.get(2));
        if (num == 0) {
            num = 1;
        }
        return Math.abs(num);
    }
}